<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="base/base :: base_head" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>发送</title>
    <!--    <link rel="stylesheet" type="text/css"
              data-th-href="@{/styles/common.css}" />
    -->
    <script type="text/javascript"
            data-th-src="@{/scripts/MyUtil.js}"></script>
    <script type="text/javascript"
            data-th-src="@{/EUI/blue/sockjs1.1.4.min.js}"></script>
    <!--<script src="http://cdn.bootcss.com/sockjs-client/1.1.1/sockjs.min.js"></script>
    <script src="http://cdn.bootcss.com/stomp.js/2.3.3/stomp.js"></script>-->
    <!--    <script type="text/javascript"
                data-th-src="@{/scripts/main/ScanTestView.js}"></script>-->
    <!--    <script type="text/javascript"
                data-th-src="@{/lang/lang_zh_CN.js}"></script>-->
    <script type="text/javascript">
        var websocket = null;
        if ('WebSocket' in window) {
            websocket = new WebSocket("ws://localhost:8090/websocket/socketServer");
        }
        else if ('MozWebSocket' in window) {
            websocket = new MozWebSocket("ws://localhost:8090/websocket/socketServer");
        }
        else {
            websocket = new SockJS("http://localhost:8090/sockjs/socketServer");
        }
        websocket.onopen = onOpen;
        websocket.onmessage = onMessage;
        websocket.onerror = onError;
        websocket.onclose = onClose;

        function onOpen(openEvt) {
            //alert(openEvt.Data);
        }

        function onMessage(evt) {
            alert(evt.data);
        }
        function onError() {}
        function onClose() {}

        function doSend() {
//            if (websocket.readyState == websocket.OPEN) {
                var msg = document.getElementById("inputMsg").value;
                websocket.send(msg);//调用后台handleTextMessage方法
                alert("发送成功!");
//            } else {
//                alert("连接失败!");
//            }
        }

        window.close=function() {
            websocket.onclose();
        }
    </script>
</head>
<body>
请输入：<textarea rows="5" cols="10" id="inputMsg" name="inputMsg"></textarea>
<button onclick="doSend();">发送</button>
</body>
</html>